package com.gem.netty.service.nobility;

import com.gem.entity.Game;
import com.gem.entity.Nobility;
import com.gem.enums.ClientMessageType;
import com.gem.enums.MessageColorType;
import com.gem.factory.game.GameFactory;
import com.gem.netty.entity.ClientContent;
import com.gem.pipeline.BusinessProcess;
import com.gem.pipeline.ProcessContext;
import com.gem.utils.R;

/**
 * Author: Xhy
 * CreateTime: 2022-09-25 13:45
 * 是否贵族库还存在贵族
 */
public class IsExistNobilityService implements BusinessProcess<ClientContent> {

    @Override
    public void process(ProcessContext<ClientContent> context) {
        Game game = GameFactory.get(context.getData().getRoomId());
        Integer no = context.getData().getContent().getNobility().getNo();
        String roomId = game.getRoomId();
        if (game.getNobilities().size() == 0 || (!Nobility.exist(roomId,no))){
            context.setNeedBreak(true);
            context.setResult(R.error().data("color", MessageColorType.SYSTEM_MESSAGE.type).message("贵族库已空").type(ClientMessageType.GET_NOBILITY.type));
        }
    }
}
